package com.gx.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;

/**
 * @Author Liu-pj
 * @Date 2022/2/23
 * @Desc Swagger配置
 **/
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class Knife4jConfig {
    /**
     * 构造api 文档
     *
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())  //文档信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gx.controller")) //包模式
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(new ArrayList<>());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("REST API")
                //描述
                .description("接口文档")
                //创建联系人信息 （作者，邮箱，网站）
                .contact(new Contact("Liu-pj", "http://www.**.com", "gx@163.com"))
                //版本
                .version("1.0")
                .build();
    }


//    private List<Parameter> parameterList() {
//        //添加全局请求头
//        List<Parameter> parameters = new ArrayList<>();
//        parameters.add(
//                new ParameterBuilder().name("Authorization")
//                        .description("用户令牌")
//                        .modelRef(new ModelRef("string"))
//                        .parameterType("header")
//                        .required(true)
//                        .build()
//        );
//        return parameters;
//    }
}
